﻿using System;
using System.Collections.Generic;

namespace DbManager.DataRequest
{
    public class DataRequestTransport:IDataRequest
    {
        private string _name =  string.Empty;
        private string _description = string.Empty;

        public void SetRequestParameters(Dictionary<string, string> parametersDictionary)
        {
            if (parametersDictionary.ContainsKey("name") && parametersDictionary.ContainsKey("description"))
            {
                _name = parametersDictionary["name"];
                _description = parametersDictionary["description"];
            }
        }

        public string GetSelectQuery()
        {
            return "SELECT [Идентификатор], [Название], [Описание] FROM [Транспорт] ORDER BY [Идентификатор]";
        }

        public string GetSelectQueryById()
        {
            throw new NotImplementedException();
        }

        public string GetInsertQuery()
        {
            if (string.IsNullOrEmpty(_name) || string.IsNullOrEmpty(_description))
            {
                return string.Empty;
            }
            return "INSERT INTO [Транспорт] ([Название], [Описание]) VALUES ('"+_name+"', '"+_description+"')";
        }

        public string GetUpdateQuery(int id)
        {
            if (string.IsNullOrEmpty(_name) || string.IsNullOrEmpty(_description) || id == 0)
            {
                return string.Empty;
            }
            return "UPDATE [Транспорт] SET [Название]='" + _name + "', [Описание]='" + _description + "' WHERE [Идентификатор]=" + id;
        }

        public string GetDeleteQuery(int id)
        {
            if (id == 0)
            {
                return string.Empty;
            }
            return "DELETE FROM [Транспорт] WHERE [Идентификатор]=" + id;
        }
    }
}
